package com.gitee.hljdrl.ffkit.fragment;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.gitee.hljdrl.ffkit.databinding.FfkitColorFragmentBinding;
import com.gitee.hljdrl.ffkit.util.FFKitUtil;

public class FFKitColorFragment extends FFKitFragment {

    /**
     * 随机颜色
     */
    public static final int MODE_RANDOM_COLOR = 1;
    /**
     * 黑白模式
     */
    public static final int MODEL_WHITE_AND_BLACK = 2;

    public static int MODE = MODE_RANDOM_COLOR;

    private FfkitColorFragmentBinding mBinding;
    private static int mNextColor = Color.WHITE;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = FfkitColorFragmentBinding.inflate(inflater);
        return mBinding.getRoot();
    }

    @Override
    public void initData() {
        View mView = getView();
        if (mView != null) {
            if (MODE == MODE_RANDOM_COLOR) {
                mView.setBackground(FFKitUtil.getRandomColorDrawable());
            } else if (MODE == MODEL_WHITE_AND_BLACK) {
                ColorDrawable drawable = new ColorDrawable(mNextColor);
                mView.setBackground(drawable);
                if (mNextColor == Color.WHITE) {
                    mNextColor = Color.BLACK;
                } else if (mNextColor == Color.BLACK) {
                    mNextColor = Color.WHITE;
                }
            }
        }

    }

    @Override
    public void initListener() {

    }
}
